package com.eatables.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.eatables.dao.EatablesMasterDao;
import com.eatables.model.TblMasterList;

public class EatablesISearchImpl extends HttpServlet implements
		EatablesISearchIfc {

	/**
    * 
    */
	private static final long serialVersionUID = -2881124848704376271L;
	public EatablesMasterDao masterDao;
	public String lat;
	public String lng;
	public String radius;
	List<com.eatables.model.TblMasterList> searchResults;

	public List<TblMasterList> getSearchResults() {
		return searchResults;
	}

	public void setSearchResults(List<TblMasterList> searchResults) {
		this.searchResults = searchResults;
	}

	public EatablesMasterDao getMasterDao() {
		return masterDao;
	}

	public void setMasterDao(EatablesMasterDao masterDao) {
		this.masterDao = masterDao;
	}

	public String getLat() {
		return lat;
	}

	public void setLat(String lat) {
		this.lat = lat;
	}

	public String getLng() {
		return lng;
	}

	public void setLng(String lng) {
		this.lng = lng;
	}

	public String getRadius() {
		return radius;
	}

	public void setRadius(String radius) {
		this.radius = radius;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		EatablesMasterDao masterDao = new EatablesMasterDao();
		PrintWriter out = response.getWriter();
		String lng = request.getParameter("lng");
		String lat = request.getParameter("lat");
		String radius = request.getParameter("radius");
		// TODO Auto-generated method stub
		System.out.print(lng + " longitude");
		System.out.print(lat + " latitude");
		System.out.print(radius + " radius");

		searchResults = masterDao.searchHotelsData(radius, lng, lat);
		System.out.println("JSON+++  " + searchResults);
		JSONArray tmpJSONObj = JSONArray.fromObject(searchResults);
		out.println(tmpJSONObj.toString());
	}

	public String searchHotelDetails() {
		// TODO Auto-generated method stub
		return null;
	}

}
